#include<iostream>
#include<string>
#include<pthread.h>
#include<unistd.h>
using namespace std;
int num = 1;
pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t _cond = PTHREAD_COND_INITIALIZER;


void* run(void* args)
{
    std::string _name = static_cast<const char*>(args);
    _name+=to_string(num++);
    while(true)
    {
        pthread_mutex_lock(&_mutex);
        pthread_cond_wait(&_cond,&_mutex);
        std::cout<<_name<<" is active"<<std::endl;
        pthread_mutex_unlock(&_mutex);
    }

}


int main()
{
    pthread_t tid1,tid2,tid3;
    pthread_create(&tid1,nullptr,run,(void*)"Thread-");
    pthread_create(&tid2,nullptr,run,(void*)"Thread-");
    pthread_create(&tid3,nullptr,run,(void*)"Thread-");


    while(true)
    {
        std::cout<<"main pthread weak thread"<<std::endl;
        pthread_cond_signal(&_cond);
        sleep(1);
    }
    pthread_join(tid1,nullptr);
    pthread_join(tid2,nullptr);
    pthread_join(tid3,nullptr);
    return 0;

}